package org.tourism.exception;

import org.tourism.common.CommonResponse;
import org.tourism.utils.result.code.Code;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.tourism.utils.result.DataResult;

@ControllerAdvice("org.tourism")
public class GlobalExceptionHandler {
    /*
     * 出现异常返回错误提示, 并且回滚事务
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public CommonResponse exceptionHandler(Exception e) {
        System.out.println("捕获异常");
        e.printStackTrace();
        //当服务器内部出错时会嘲讽前端
        return CommonResponse.createForError(500, "嘻嘻，异常，嘻嘻");
    }

}
